<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="inputlib" uri="/WEB-INF/taglibs-input.tld" %>
<%@ page import="tau.dimes.config.login.LoginConfiguration"%>
<%@page import="java.util.Date"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="login" class="tau.dimes.beans.LoginBean" scope="session" />
<%
	String root = application.getContextPath();
	String errorMessage = "";
%>
<%
	if (request.getMethod().equalsIgnoreCase("post"))
	{
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		if (username != null || password != null)
			if (LoginConfiguration.validate(username, password))
			{
				login.setUsername(username);
				login.setLoginTime(new Date());
				login.setLoggedIn(true);

				String returnUrl = request.getParameter("returnUrl");

				String redirectUrl = (returnUrl != null) ? returnUrl : root;
				response.sendRedirect(redirectUrl);
			}
			else
			{
				errorMessage = "Login failed. Check your username and password";
			}		
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dimes - Login</title>
<link type="text/css" rel="stylesheet" href="<%=root%>/styles/header.css" />
<script type="text/javascript" src="<%=root%>/script/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<%=root%>/script/login.js"></script>
</head>
<body>
<table id="title">
	<tr>
		<td><img alt="DIMES" src="<%=root%>/images/DIMES.gif"></td>
		<td><span>DIMES Visualization</span></td>
	</tr>
</table>
<div id="topmenu">
<table>
	<tr>
		<td><a id="login" class="active" href="<%=root%>/pages/Login.jsp">Login</a></td>
	</tr>
</table>
</div>
<form method="post">
<input type="hidden" id="errorMessage" value="<%=errorMessage%>"/>
<table cellpadding="1px" cellspacing="1px">
	<tr>
		<td>
			<label>User Name: </label>
		</td>
		<td>
			<input type="text" id="username" name="username" />
		</td>
	</tr>
	<tr>
		<td>
			<label>Password: </label>
		</td>
		<td>
			<input type="password" id="password" name="password" />
		</td>
	</tr>
</table>
<input type="submit" id="btnLogin" value="Login" /><input type="reset" /></form>

</body>
</html>